<!--
 * @Author: your name
 * @Date: 2020-03-30 21:21:36
 * @LastEditTime: 2020-04-02 22:46:17
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \vue-imooc-ebook\src\components\ebook\EbookSettingTheme.vue
 -->
<template>
  <transition name="slide-up">
    <div class="setting-wrapper" v-show="menuVisible && settingVisible === 1">
      <div class="setting-theme">
        <div class="setting-theme-item" v-for="(item, index) in themeList" :key="index" @click="setTheme(index)">
          <div class="preview" :class="{'selected': item.name === defaultTheme}" :style="{background: item.style.body.background}"></div>
          <!-- 国际化的方式进行显示 -->
          <div class="text" :class="{'selected': item.name === defaultTheme}">{{item.alias}}</div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
  import { ebookMixin } from '../../utils/mixin'
  import { themeList } from '../../utils/book'
  import { saveTheme } from '../../utils/localStorage'
  export default {
    mixins: [ebookMixin],
    // data() {
    //   return {
      // 主题列表,在utils里的book.js中
      // 代码写在mixin中混入了
    //     // themeList: THEME_LIST
    //     themeList: themeList(this)
    //   }
    // }
    // data写成计算属性，不用频繁调用
    methods: {
      setTheme(index) {
        const theme = this.themeList[index]
        this.setDefaultTheme(theme.name).then(() => {
          // 设置电子书主题
          this.currentBook.rendition.themes.select(this.defaultTheme)
          // 全局主题切换,在mixin中
          this.initGlobalStyle()
        })
        saveTheme(this.fileName, theme.name)
      }
    }
  }
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
  @import "../../assets/styles/global";
    .setting-wrapper {
      position: absolute;
      bottom: px2rem(86);//48
      left: 0;
      z-index: 190;
      width: 100%;
      height: px2rem(220);
      background: white;
      box-shadow: 0 px2rem(-8) px2rem(8) rgba(0, 0, 0, .15);
      .setting-theme {
        height: 100%;
        display: flex;
        .setting-theme-item {
          flex: 1;
          display: flex;
          flex-direction: column;
          padding: px2rem(5);
          box-sizing: border-box;
          .preview {
            flex: 1;
            border: px2rem(1) solid #ccc;
            box-sizing: border-box;
            &.selected {
              box-shadow: 0 px2rem(4) px2rem(6) 0 rgba(0,0,0,.1);
            }
          }
          .text {
            flex: 0 0 px2rem(80);//20
            font-size: px2rem(33);//14
            color: #ccc;
            @include center;
            &.selected {
              color: #333;
            }
          }
        }
      }
    }
</style>
